#pragma once

#include "../../base/obj_pointer.h"
#include "../../vmath/vec2i.h"
#include "../../vmath/vec2.h"
#include "texture.h"

OPEN_JLIB_NS


struct FrameBuffer : public Obj {

  bool init (Texture* colorBuf);
  bool init (Texture* colorBuf, Texture* depthBuf, Texture* stencilBuf);

  bool drawable ();
  void use ();
  void unuse ();
  void clear ();

  inline bool valid () const noexcept { return _fb != 0; }
  inline s32 width () const noexcept { return _colorBuf->width(); }
  inline s32 height () const noexcept { return _colorBuf->height(); }
  inline Vec2i size () const noexcept { return _colorBuf->size(); }
  inline Ptr<Texture> colorTexture () noexcept { return _colorBuf; }
  inline Ptr<Texture> depthTexture () noexcept { return _depthBuf; }
  inline Ptr<Texture> stencilTexture () noexcept { return _stencilBuf ? _stencilBuf : _depthBuf; }

protected:
  Ptr<Texture> _colorBuf;
  Ptr<Texture> _depthBuf;
  Ptr<Texture> _stencilBuf;
  GLuint _rb {0};
  GLuint _fb {0};
  GLuint _ofb {0};
};


CLOSE_JLIB_NS
